package main.UI.misc;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Created with IntelliJ IDEA.
 * User: Sknictik
 * Date: 29.11.13
 * Time: 23:42
 * To change this template use File | Settings | File Templates.
 */
public class PopupListener extends MouseAdapter {

    public PopupListener(){
    }

    @Override
    public void mousePressed(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON3)
        {
            JTable table;
            if (e.getComponent() instanceof JTable)
                table = (JTable) e.getComponent();
            else throw new IllegalArgumentException("Слушатель получил неправильный объект");
            int r = table.rowAtPoint(e.getPoint());
            try {
                table.setRowSelectionInterval(r, r);
            }
            catch (IllegalArgumentException ex)
            {
                System.out.println("Клик правой кнопкой вне значений таблицы");
            }
        }
    }
}
